class Person implements Cloneable {
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}


public class Test {
    public static void func(int a) {
/*        try {
            System.out. println(10/a);
        } catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println("a==0");
        }*/
        System.out. println(10/a);
    }
    public static void main(String[] args) {
        try {
            func(0);
        }catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println("a==0");
        }
    }
    public static void main4(String[] args) {
        System.out.println("befor");
        try {
            System.out.println(10/0);
            //不会捕捉这个异常，先捕获到哪个异常就处理哪个异常
            int[] array = null;
            System.out.println(array.length);
            System.out.println("232");//不会执行
        }
/*        catch (ArithmeticException | NullPointerException e) {
            System.out.println("0000");
        } */
        catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println("捕获到了算数异常,这里一般处理异常");
        }catch(NullPointerException e) {
            //e.printStackTrace();
            System.out.println("捕获空指针异常");
        }finally {
            System.out.println("finally 执行了");
        }
        System.out.println("after");
    }
    public static void main3(String[] args) {
        Person person = new Person();
        try {
            Person person1 = (Person) person.clone();
        } catch (CloneNotSupportedException e) {
            System.out.println("11");
            throw new RuntimeException(e);
        }
        System.out.println("222");
    }
    public static void main2(String[] args) {
        int a = 10;
        //抛出一个指定的异常
        //一般我们会通过throw抛出一些自己自定义的异常
        if(a == 10) {
            throw new NullPointerException();
        }
    }
    public static void test() {
        test();
    }

    public static void main1(String[] args) {
        System.out.println(20/0);//算数异常
        int[] array = null;//空指针异常
        int[] array2 = {1,2,3};
        System.out.println(array2[100]);//数组越界异常
        System.out.println(array.length);
        test();
    }
}
